/**
 * 快排序， 递归
 */

const arrs = [1, 4, 5, 6, 7, 8, 10, 0, 2, 0, 90, 98, 18]

function quickSort(arrs) {
    if(arrs.length <= 1) return arrs

    let len = arrs.length, leftArr = [], rightArr = []
    const provitIndex = Math.floor(len / 2)
    const provit = arrs.slice(provitIndex, 1)[0]
    len -=1

    for (let i = 0; i < len - 1; i++) {
        const cur = arrs[i]
        if (cur < provit) {
            leftArr.push(cur)
        } else {
            rightArr.push(cur)
        }
    }

    return [...quickSort(leftArr), provit, ...quickSort(rightArr)]
}

console.log(quickSort(arrs));
